/* Turska Framework/UI library (Turs2)
 * Copyright 2003-2008 Jetro Lauha
 * All rights reserved.
 * Web: http://iki.fi/jetro/turska/
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of EITHER:
 *   (1) The GNU Lesser General Public License as published by the Free
 *       Software Foundation; either version 2.1 of the License, or (at
 *       your option) any later version. The text of the GNU Lesser
 *       General Public License is included with this library in the
 *       file LICENSE-LGPL.txt.
 *   (2) The BSD-style license that is included with this library in
 *       the file LICENSE-BSD.txt.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files
 * LICENSE-LGPL.txt and LICENSE-BSD.txt for more details.
 *
 * $Id: App.h 73 2008-07-07 19:06:57Z jlauha $
 * $Revision: 73 $
 */

#ifndef APP_H_INCL
#define APP_H_INCL


#include <assert.h>


class AppState;


class App
{
public:

    App();
    virtual ~App();

    // App:
    static void setInstance(App *singleton);
    static App * getInstance()
    {
        assert(mSingleton != NULL);
        return mSingleton;
    }

    virtual bool init();

    virtual void run();

    virtual void render() {}

    virtual void setAppStateHandler(AppState *state);
    AppState * getCurrentAppStateHandler() { return mCurrentAppStateHandler; }

    void setAlive(bool alive) { mAlive = alive; }
    bool isAlive() const { return mAlive; }

    UI32 getTime() { return mTime; }

    Graphics * getGraphics() { return mGraphics; }

    // SDL/OpenGL-specific:

    SDL_Surface * getScreen() const { return mScreen; }

    I32 getScreenWidth() { return getScreen()->w; }
    I32 getScreenHeight() { return getScreen()->h; }

protected:

    virtual bool update();

    void resetTime();

    virtual C8 * getWindowCaption();

    static App *mSingleton;

    bool mAlive;
    UI32 mTime, mStartTime;
    double mNextUpdateTime;

    AppState *mCurrentAppStateHandler;

    I32 mMouseX, mMouseY;
    I32 mPreviousMouseX, mPreviousMouseY;

    Graphics *mGraphics;

    SDL_Surface *mScreen;
};


#endif // !APP_H_INCL
